//
//  ViewController.m
//  iOSProject
//
//  Created by Charles on 2020/2/22.
//  Copyright © 2020 Charles. All rights reserved.
//

#import "ViewController.h"
#import <Flutter/Flutter.h>
#import <flutter_boost/FlutterBoostPlugin.h>
#import "NativeViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    UIButton *pushButton = [UIButton buttonWithType:UIButtonTypeCustom];
    pushButton.backgroundColor = [UIColor redColor];
    pushButton.layer.cornerRadius = 25;
    pushButton.clipsToBounds = YES;
    pushButton.frame = CGRectMake(0, 0, 200, 50);
    pushButton.center = CGPointMake(self.view.center.x, self.view.center.y - 150);
    [pushButton setTitle:@"Push Flutter Page" forState:UIControlStateNormal];
    [pushButton addTarget:self action:@selector(pushEvent) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:pushButton];
    
    UIButton *presentButton = [UIButton buttonWithType:UIButtonTypeCustom];
    presentButton.backgroundColor = [UIColor redColor];
    presentButton.layer.cornerRadius = 25;
    presentButton.clipsToBounds = YES;
    presentButton.frame = CGRectMake((self.view.bounds.size.width - 200)/2, CGRectGetMaxY(pushButton.frame) + 50, 200, 50);
    [presentButton setTitle:@"Present Flutter Page" forState:UIControlStateNormal];
    [presentButton addTarget:self action:@selector(presentEvent) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:presentButton];
    
    UIButton *embededButton = [UIButton buttonWithType:UIButtonTypeCustom];
    embededButton.frame = CGRectMake((self.view.frame.size.width - 200)/2, CGRectGetMaxY(presentButton.frame) + 50, 200, 50);
    embededButton.layer.cornerRadius = 25;
    embededButton.clipsToBounds = YES;
    embededButton.backgroundColor = [UIColor redColor];
    [embededButton setTitle:@"push embeded" forState:UIControlStateNormal];
    [embededButton addTarget:self action:@selector(embededEvent) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:embededButton];
}

- (void)pushEvent {
    [FlutterBoostPlugin open:@"first" urlParams:@{kPageCallBackId:@"MycallbackId#1"} exts:@{@"animated":@(YES)} onPageFinished:^(NSDictionary * result) {
        NSLog(@"call me when page finished, and your result is:%@",result);
    } completion:^(BOOL finish) {
        NSLog(@"page is opened");
    }];
}

- (void)presentEvent {
    [FlutterBoostPlugin open:@"second" urlParams:@{@"present":@(YES),kPageCallBackId:@"MycallbackId#2"} exts:@{@"animated":@(YES)} onPageFinished:^(NSDictionary *result) {
        NSLog(@"call me when page finished, and your result is:%@", result);
    } completion:^(BOOL f) {
        NSLog(@"page is presented");
    }];
}

- (void)embededEvent{
    UIViewController *vc = [[NativeViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}


@end
